package com.j.lemon.learn.basic.OkHttp3;

import sun.net.spi.DefaultProxySelector;

import java.net.Proxy;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lijunjun
 */
public class RetryableProxy extends DefaultProxySelector {
    int count;

    public RetryableProxy(int count) {
        this.count = count;
    }

    @Override
    public List<Proxy> select(URI uri) {
        List<Proxy> proxyList = new ArrayList<>(count);
        List<Proxy> select = super.select(uri);
        for (int i = 0; i < count; i++) {
            proxyList.addAll(select);
        }
        return proxyList;
    }
}
